<?php
  class Actualite_m extends Model{
      function Actualite_m(){
          parent::Model();
          $this->load->database();
      }
      function get_all_news($per_page,$off_set){
          $this->db->select('actu.id,actu.nomfr,actu.img,catactu.nomfr as cat_name');
          $this->db->from('actu');
          $this->db->join('catactu','actu.catid=catactu.id');
          $this->db->limit($per_page,$off_set);
          $query = $this->db->get();
          return $query->result_array();
      }
      function add_news($data){
          return $this->db->insert('actu',$data);
      }
      function get_news_by_id($id){
          $query=$this->db->get_where('actu',array('id'=>$id));
          return $query;
      }
      function update_news($data,$id){
          return $this->db->update('actu',$data,array('id'=>$id));
      }
      function delete_news($id){
          return $this->db->delete('actu',array('id'=>$id));
      }
      function get_all_categories($per_page, $off_set){
          $this->db->select();
          $this->db->from('catactu');
          $this->db->limit($per_page,$off_set);
          $query = $this->db->get();
          return $query->result_array();
      }
      function delete_news_cat($id){
          return $this->db->delete('catactu',array('id'=>$id));
      }

      function add_news_cat($data){
          return $this->db->insert('catactu',$data);
      }

      function update_news_cat($data,$id){
          return $this->db->update('catactu',$data,array('id'=>$id));
      }

      function get_news_cat_by_id($id){
          $query=$this->db->get_where('catactu',array('id'=>$id));
          return $query;
      }
  }
?>
